import paramiko

host: str = '192.168.10.233'
port: int = 22
username: str = 'root'
password: str = 'jg+705'
local_file: str = '../../target/weather_spider.jar'
remote_file: str = '/home/weather_spider/weather_spider.jar'
command: str = 'docker restart weather_spider'
# 创建ssh客户端
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)

# 连接远程服务器
ssh.connect(hostname=host, port=port, username=username, password=password)

# 打开sftp会话
sftp = ssh.open_sftp()
sftp.put(local_file, remote_file)
sftp.close()

# 执行命令
stdin, stdout, stderr = ssh.exec_command(command=command)
print(stdout.read().decode())

ssh.close()